/**
 * http请求封装
 */
import request from './request';
// enum 枚举
enum requestType {
    GET = 'get',
    POST = 'post'
}

type Config = {
    method: string,
    url: string,
    data?: any,
    params?: any,
    headers?: any
    loading?: boolean,
}

/**
 * @method 请求类型
 * @param url 请求api路径
 * @param params 请求参数
 * @returns Promise
 */
const http = {
    //get请求
    get(url: string, params: any, extra: any) {
        const config: Config = {
            method: requestType.GET,
            url
        }
        if(params) {
            config.params = params;
        }
        config.loading = extra.loading || false;
        return request(config);
    },
    //post请求
    post(url: string, params: any, extra: any) {
        const config: Config = {
            method: requestType.POST,
            url
        }
        if(params) {
            config.data = params;
        }
        config.loading = extra.loading || false;
        return request(config);
    }
}

export default http;
